package com.example.to_dolist;

import java.util.ArrayList;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;


public class ToDoListActivity extends Activity  implements OnClickListener, OnLongClickListener{
	Button m_addButton;  
	View m_itemListView; 
	View m_newView;
	String ToDoItem;
	ArrayList<View> tester = new ArrayList<View>(); 
		
	public boolean onLongClick(View v){
		TextView tv = (TextView) v;
		String message = tv.getText().toString();
		
		Intent smsIntent = new Intent(Intent.ACTION_VIEW);
		
		smsIntent.putExtra("sms_body", "To-Do List Item: " + message);
		smsIntent.putExtra("address",  "");
		smsIntent.setType("vnd.android-dir/mms-sms");
		
		try {
		    startActivity(smsIntent);
		} catch (ActivityNotFoundException e) {
		    // Display some sort of error message here.
		}
		return false;
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_to_do_list);
		initLayout1();
		m_addButton.setOnClickListener(this);
	}
	public void initLayout1(){
	m_addButton = (Button) this.findViewById(R.id.button1);
	m_itemListView = (LinearLayout) this.findViewById(R.id.To_Do_List_View);
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_to_do_list, menu);
		return true;
	}	
	@Override
	public void onClick(View arg0) {

		// TODO Auto-generated method stub
		//ToDoItem = m_editText.getText().toString();
      	//addToDoItem();
		//String newItem =m_editText.getText().toString();
		
		Intent i = new Intent(this, MainActivity2.class);
		startActivityForResult(i, 1234567);
	}
	public void removeAllViews(){
		//this method will remove the view with the old items.
	((ViewGroup)m_itemListView).removeView(m_itemListView);
	}
	public void populateToDoItems(View d){
		//((ViewGroup) m_itemListView).addView(newItemTextView);
		tester.add(m_itemListView);
		tester.add(d);
	}
	public void updateLayout(View c){
		//removeAllViews();
		populateToDoItems(c);
	}	
	protected void onActivityResult(int requestCode, int resultCode, View data) {
		 if( requestCode == 1234567 ) {
			 if (resultCode == RESULT_OK) {
		        // updateLayout(data);  			 
		            // Do something with the contact here (bigger example below)
		        }

		    }
	
		 }//onActivityResult
	
	
	
	
	
}



